package jsonmap

import (
	"errors"
	"reflect"
)

func AnyToAny(from interface{}, to interface{}) (err error) {
	fromref := reflect.ValueOf(from)
	toref := reflect.ValueOf(to)
	switch fromref.Kind() {
	case reflect.Map:
		switch toref.Kind() {
		case reflect.Map:
			MapToJsonMap(from.(map[string]interface{}), to.(map[string]interface{}))
		case reflect.Struct:
			err = MapToStruct(from.(map[string]interface{}), toref.Addr())
		case reflect.Ptr:
			err = MapToStruct(from.(map[string]interface{}), to)
		}
	case reflect.Struct:
		switch toref.Kind() {
		case reflect.Map:
			err = StructToMap(from.(map[string]interface{}), to.(map[string]interface{}))
		case reflect.Struct:
			err = errors.New("not support")
		}
	}

	return
}
